package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.dto.UserLoginDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.DishService;
import com.sky.service.SetMealService;
import com.sky.service.UserService;
import com.sky.vo.DishItemVO;
import com.sky.vo.UserLoginVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private DishService dishService;

    @Autowired
    private SetMealService setmealService;


    /**
     * 微信登录
     * @param code
     * @return
     */
    @PostMapping("/user/login")
    public Result<UserLoginVO> loginByWeChat(@RequestBody UserLoginDTO code){
        log.info("临时授权：{}" + code);
        return userService.loginByWeChat(code);
    }

    /**
     * 这是拿菜品的list
     * @param type
     * @return
     */
    @GetMapping("/category/list")
    public Result getCategoryList(Integer type){
        log.info("开始拿categorylist");
        return categoryService.getCategoryList(type);
    }



    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/dish/list")
    public Result<List<Dish>> userDishList(Long categoryId){
        List<Dish> list = dishService.list(categoryId);
        return Result.success(list);
    }


    /**
     * 条件查询
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/setmeal/list")
    public Result<List<Setmeal>> list(Long categoryId) {
        return setmealService.list(categoryId);
    }

    /**
     * 根据套餐id查询包含的菜品列表
     *
     * @param id
     * @return
     */
    @GetMapping("/setmeal/dish/{id}")
    public Result<List<DishItemVO>> getDishItemById(@PathVariable("id") Long id) {
        return setmealService.getDishItemById(id);
    }

}
